package com.aistar.servlet;

import com.aistar.pojo.Shop;
import com.aistar.service.ShopService;
import com.aistar.service.impl.ShopServiceImpl;
import com.github.pagehelper.PageInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "ShopAllServlet",urlPatterns = "/shop/all")
public class ShopAllServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String pageStr=request.getParameter("page");
        Integer pageNum=null;
        if (pageStr==null)
            pageNum=1;
        else
            pageNum=Integer.valueOf(pageStr);

        ShopService shopService=new ShopServiceImpl();
        PageInfo<Shop> shopPageInfo=shopService.getAll(pageNum,3);

        request.setAttribute("shopList",shopPageInfo.getList());
        request.setAttribute("page",shopPageInfo);
        //4. 页面跳转
        request.getRequestDispatcher("/shop/all.jsp").forward(request,response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
